package engine.graphics;

import java.io.Serializable;

import org.newdawn.slick.opengl.Texture;

import engine.system.ID;

public class Sprite implements Serializable{
	
	private static final long serialVersionUID = 1L;
	
	private QuadTexUV texCoords ; 
	
	public QuadTexUV getTexCoords(){
		return this.texCoords; 
	}
	
	private Sprite(QuadTexUV coords){
		this.texCoords = coords ; 
	}
	
	public static Sprite getTextureByTexID(Texture tex, int texWidth, int texHeight, ID texID){
		float x = (1 / (float)((tex.getImageWidth() / (float)texWidth))) ; 
		float y = (1 / (float)((tex.getImageHeight() / (float)texHeight))) ; 
		float x1 =  x * texID.getX(); 
		float x2 = x1 + x;
		float y1 =  y * texID.getY(); 
		float y2 = y1 + y;
		return new Sprite(new QuadTexUV(new TexUV[]{new TexUV(x1,y1),
														new TexUV(x2,y1),
														new TexUV(x2,y2),
														new TexUV(x1,y2)})); 
	}
	
	public static Sprite getTextureByImageCoords(Texture tex, Vertex2f imgSize, Vertex2f imgCoords){
		float w = (1 / (float)tex.getImageHeight()) * imgSize.getX() ; 
		float h = (1 / (float)tex.getImageHeight()) * imgSize.getY(); 
		float x1 = (1 / (float)tex.getImageWidth()) * imgCoords.getX();
		float x2 = x1 + w ;
		float y1 = (1 / (float)tex.getImageWidth()) * imgCoords.getY();
		float y2 = y1 + h ;
		return new Sprite(new QuadTexUV(new TexUV[]{new TexUV(x1,y1),
													new TexUV(x2,y1),
													new TexUV(x2,y2),
													new TexUV(x1,y2)})); 
	}
	
}
